package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author 冰白寒祭
 * @date 2023-09-02 16:07:42
 * @description 店铺状态
 */
@Api(tags = "店铺相关接口")
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
public class ShopController {


    public static final String KEY = "SHOP STATUS";

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;


    /**
     * @MethodName: setStatus
     * @Author 冰白寒祭
     * @Description: 设置店铺的营业状态
     * @Date: 2023-09-02 16:11:25
     * @param: status
     * @return: Result
     */

    @PutMapping("/{status}")
    @ApiOperation("设置店铺的营业状态")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺的营业状态为{}", status == 1 ? "营业中" : "已打烊");
        redisTemplate.opsForValue().set(KEY, status);
        return Result.success();
    }


    /**
     * @MethodName: getStatus
     * @Author 冰白寒祭
     * @Description: 获取店铺营业状态
     * @Date: 2023-09-02 16:17:04
     * @param: a
     * @return: Result<Integer>
     */

    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> getStatus() {
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        assert status != null : "状态获取失败";
        log.info("当前店铺营业状态为:{}", status == 1 ? "营业中" : "已打烊");
        return Result.success(status);
    }

}
